package com.shetuan.servelt;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shetuan.bean.Member;
import com.shetuan.dao.MemberDao;

/**
 * 成员信息Servlet
 * * @author Administrator
 */
public class MemberInfoServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 获取界面传来的成员姓名
        String membername = request.getParameter("mname");
        // [FIXED] 获取用于判断来源的参数
        String from = request.getParameter("from");

        System.out.println(membername);
        // 调用memberdao方法获取member
        MemberDao memberDao = new MemberDao();
        Member member = memberDao.getMemberByName(membername);
        System.out.println(member);
        request.setAttribute("member", member);

        // [FIXED] 根据 'from' 参数的值决定跳转到哪个页面
        if ("index".equals(from)) {
            // 如果参数 from=index (来自index2.jsp)，则跳转到 memberInfo2.jsp
            request.getRequestDispatcher("admin/memberInfo2.jsp").forward(request, response);
        } else {
            // 否则，保持默认跳转 (来自member_list.jsp)，跳转到 memberInfo.jsp
            request.getRequestDispatcher("admin/memberInfo.jsp").forward(request, response);
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

}